
from visual import *
from Brain.vector import Vector

def cc(value):
	return value / 255.0

class Robot:
	""" Represents robot
	"""
	def __init__(self):
		self._frame = frame(up=(0,0,1))
		## length ---> X; width ---> Z; height ---> Y
		self._direction_arrow = arrow(frame=self._frame, pos=(90,175,0), axis=(120,0,0), shaftwidth=100, color=(cc(171),cc(230),cc(168)), up=(0,0,1))
		self._base, _array_ = [], []
		array = [
			[ (-40,20, -172.5), (205,20, -172.5), (205,20, -125), (-40,20, -125),  ],
			[ (-40,20, -125), (205,20, -125), (100,20, -40), (-40,20, -40),  ],
			[ (-40,20, -40), (100,20, -40), (100,20, 40), (-40,20, 40),  ],
			[ (-40,20, 40), (100,20, 40), (205,20, 125), (-40,20, 125),  ],
			[ (-40,20, 125), (205,20, 125), (205,20, 172.5), (-40,20, 172.5),  ],
			]
		for half in array:
			duplicate = []
			for x in half:
				duplicate.append( (x[0], x[1]+70, x[2], ) )
			_array_.append( half + duplicate )
		for _box_ in _array_:
			element = convex(frame=self._frame, pos=_box_	, color=(cc(121),cc(140),cc(189)), up=(0,0,1))
			##element.opacity = 0.7
			self._base.append( element )
		
		self._t = 0
		self._toggle = False

	def move(self, new_position):
		self._frame.pos = new_position

	def rotate(self, direction):
		if direction:
			axis = ( direction.x, direction.y, 0.0 )
			self._frame.axis = axis
		else:
			self._frame.axis = (1,0,0)
	
	def blink(self):
		if self._t > 15:
			val = int(self._toggle)
			##self._base.visible = int(self._toggle)
			for el in self._base:
				el.visible = val
			self._toggle = not self._toggle
			self._t = 0
		else:
			self._t += 1
